import "./../sass/register.scss";
import "./../sass/reset.scss";
import "./../libs/jquery.validate.min";
import $ from "jquery";
import $fn from "./register-fn"
const layer = require('layui-layer');


$(function () {
    $.validator.addMethod("chckePhone", function (value, ele, params) {
        var reg = /^[1]\d{10}$/;
        return reg.test(value);
    })
    $("#reg").validate({
        rules: {
            uname: {
                required: true,
                rangelength: [6, 16]
            },
            upwd: {
                required: true,
                rangelength: [6, 16]
            },
            uphone: {
                chckePhone: true,
            }
        },
        messages: {
            uname: {
                required: "用户名必填",
                rangelength: "用户名的长度{0}-{1}"
            },
            upwd: {
                required: "密码必填",
                rangelength: "密码的长度{0}-{1}"
            },
            uphone: {
                chckePhone: "手机号不合法",
            }
        },
        submitHandler() {

            
                $.ajax({
                    url: "http://10.41.151.55:8081/api/reg",
                    type: "post",
                    data: $("#reg").serialize(),
                    dataType: "json",

                }).then(function (res) {
                    console.log(res)
                    layer.msg(res.msg, { icon: res.status == 200 ? 1 : 2 });
                    
                    if (res.status == 200) {
                        setTimeout(function(){ 
                            window.location.href = 'http://localhost:8080/login.html' 
                        }, 1500);
                    }
                })
            return false;
        }
        
    })
})


$(function () {
    $fn.banner()
})